import { createApp } from 'vue'
import App from './App.vue'
import { setupVab } from '~/library'
import { setupI18n } from '@/i18n'
import { setupStore } from '@/store'
import { setupRouter } from '@/router'

/**
 * @description 正式环境默认使用mock，正式项目记得注释后再打包
 */
import { baseURL, pwa, microAppList } from './config'
import { isExternal } from '@/utils/validate'

import { registerMicroApps, addGlobalUncaughtErrorHandler } from 'qiankun'
// loadMicroApp

const app = createApp(App)

if (process.env.NODE_ENV === 'production' && !isExternal(baseURL)) {
  const { mockXHR } = require('@/utils/static')
  mockXHR()
}

/**
 * @description 生产环境启用组件初始化，编译，渲染和补丁性能跟踪。仅在开发模式和支持 Performance.mark API的浏览器中工作。
 */
//if (process.env.NODE_ENV === 'development') app.config.performance = true

if (pwa) require('./registerServiceWorker')

localStorage.setItem('ceshi', '12122')

setupVab(app)
setupI18n(app)
setupStore(app)
setupRouter(app)
  .isReady()
  .then(() => app.mount('#app'))

registerMicroApps(microAppList)
// 启动 qiankun
// start(
//   {
//     //   sandbox: {
//     //     strictStyleIsolation: true,
//     //   },
//     singular: false, // 同时激活多个微应用
//   }
// )

// 添加全局异常捕获
addGlobalUncaughtErrorHandler((handler) => {
  console.log('异常捕获', handler)
})
// nextTick(() => {
//   loadMicroApp({
//     name: 'child',
//     entry: '//localhost:21000',
//     container: '#child-container',
//   })
// })

// start({
//   sandbox: {
//     strictStyleIsolation: true, // 严格沙箱
//     experimentalStyleIsolation: true, // 实验性沙箱
//   },
// })
